package com.wondersgroup.fjzlpt.org.controller.view.jgqy.jrylt;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.quick.framework.util.QuickPrincipalUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.druid.util.StringUtils;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.quick.framework.boot.web.utils.RequestUtils;
import com.quick.framework.boot.web.wapper.QuickPrincipal;
import com.wondersgroup.fjzlpt.org.dao.inter.jgqy.qysq.QysqDAO;
import com.wondersgroup.fjzlpt.org.dao.inter.jgqy.qysq.QysqKsxxDAO;
import com.wondersgroup.fjzlpt.org.dao.inter.yljgxx.YljgxxDAO;
import com.wondersgroup.fjzlpt.org.service.inter.jgqy.jrylt.JryltService;

@Controller
@RequestMapping("jrylt")
public class JryltController {
	
	@Autowired
	private YljgxxDAO yljgxxDAO;
	
	@Autowired
	private QysqDAO qysqDAO;
	
	@Autowired
	private JryltService jryltService;
	
	@Autowired
	private QysqKsxxDAO qysqKsxxDAO;
	
	@RequestMapping("/index.html")
	public String index(HttpServletRequest request)
	{
        JSONObject json = new JSONObject();
        json.put("PTJGID", QuickPrincipalUtils.getPtjgID(request));
        request.setAttribute("userInfo", json);
		return "jgqy/jrylt/index";
	}
	
	@RequestMapping("/manager.html")
	public String manager(HttpServletRequest request)
	{
		Map<String, String> map = RequestUtils.GetParameterMap(request);
		if(map.containsKey("YLJGID")){
			/**获取签约申请机构信息*/ 
			map.put("pageSize", "1");
			map.put("pageNumber", "1");
			JSONObject jo = yljgxxDAO.queryPage(map);
			request.setAttribute("fqyljgxx", jo.get("rows"));
		}
		return "jgqy/jrylt/manager";
	}
	
	@RequestMapping("/detail.html")
	public String detail(HttpServletRequest request)
	{
		Map<String, String> map = RequestUtils.GetParameterMap(request);
		if(map.containsKey("YLTID")){
			/**获取医联体信息*/
			map.put("pageSize", "1");
			map.put("pageNumber", "1");
			String yljgid = map.remove("YLJGID");
			JSONObject jo = qysqDAO.queryYltxx(map);
			jo = (JSONObject) (jo.getJSONArray("rows")).get(0);
			request.setAttribute("qysqxx", jo);
			/**获取签约机构信息*/
			map.put("YLTLX", jo.getString("YLTLX"));
			JSONArray ja = jryltService.queryQyJg(map);
			request.setAttribute("qyjgxx", ja);
			map.put("YLJGID", yljgid);
			map.put("pageSize", "1");
			map.put("pageNumber", "1");
			JSONObject json = yljgxxDAO.queryPage(map);
			json = (JSONObject) (json.getJSONArray("rows")).get(0);
			/**专科联盟下，还需获取主导机构的科室信息*/
			if("03".equals(map.get("YLTLX"))){
				json.putAll(jryltService.querZdjgKsxx(map));
			}
			request.setAttribute("fqyljgxx", json);
		}
		return "jgqy/jrylt/detail";
	}
	
	@RequestMapping("/ylt.html")
	public String ylt(HttpServletRequest request)
	{
		return "jgqy/jrylt/ylt";
	}
	
	@RequestMapping("/kslb.html")
	public String kslb(HttpServletRequest request)
	{
		return "jgqy/jrylt/kslb";
	}
	
}
